package com.ketai.appinfo.controller;
import com.ketai.appinfo.pojo.BackendUser;
import com.ketai.appinfo.service.BackendUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 *@Author 刘玉琼
 *@Time 2020-11-03
 *
 */
@Controller
@RequestMapping("/managerController")
public class ManagerController {

    @Resource
   private BackendUserService backendUserService;
    @RequestMapping( path = "/toLogin", method = RequestMethod.GET)
    public String getManageToLogin(){
        return "/backendlogin";
    }
    /**
     * 登录
     * @param userCode
     * @param userPassword
     * @return
     */
    @RequestMapping( path = "/login", method = RequestMethod.POST)
    public String getManageLogin(String userCode, String userPassword, HttpSession session) {
        BackendUser user=backendUserService.backUserLogin(userCode,userPassword);
        if (user==null){
            return "/backendlogin";
        }
        session.setAttribute("userSession",user);
        return  "/backend/main";
    }

    /**
     *注销
     * @param session
     * @return
     */
        @RequestMapping( path = "/logout", method = RequestMethod.GET)
    public String loginOut(HttpSession session) {
        session.removeAttribute("userSession");
        return  "backendlogin";
    }
}
